﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Chat_Model.ViewModel
{
    public class LarTalkListProfile : Profile
    {
        public LarTalkListProfile()
        {
            CreateMap<LarTalkList, LarTalkListDto>()
                .ForMember(
                item => item.Avatar, item => item.MapFrom(item =>
                item.TalkType == 1 ? item.LarUsers.Avatar : (item.TalkType == 2 ? item.LarGroup.Avatar : "")
                ))
                .ForMember(
                item => item.Name, item => item.MapFrom(item =>
                item.TalkType == 1 ? item.LarUsers.Nickname : (item.TalkType == 2 ? item.LarGroup.GroupName : "")
                ))
                .ForMember(
                item => item.Remark_name, item => item.MapFrom(item =>
              item.TalkType == 1 ? item.LarUsers.Nickname : (item.TalkType == 2 ? item.LarGroup.GroupName : "")
                ))
                .ForMember(
                item => item.Unread_num, item => item.MapFrom(item => item.LarTalkRecordsList.Select(x => x.IsRead == 0).Count())
                )
                 .ForMember(
                item => item.Msg_Text, item => item.MapFrom(item => item.LarTalkRecordsList.OrderByDescending(x => x.CreatedAt).FirstOrDefault().Content)
                )
                  .ForMember(
                item => item.Friend_id, item => item.MapFrom(item => item.LarUsers.Id)
                )
                   .ForMember(
                item => item.Group_id, item => item.MapFrom(item => item.LarGroup.Id)
                )
                ;
        }
    }
}
